/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:25 AM
------------------------------------------------------*/
using hou_elearning.Entity;
using hou_elearning.DataAccess;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
namespace hou_elearning.Business
{
    public class DanhmucsukienslideBRL
    {
        #region Init
        private static string EX_NOT_EXIST="Không Tồn Tại Danhmucsukienslide Này";
		private static string EX_STENSUKIEN_EMPTY="sTendanhmuc không được để trống";
		private static string EX_ID_INVALID="PK_sDanhmucsukienslideID không hợp lệ";
        #endregion
        #region Public Methods
        /// <summary>
        /// Get Danhmucsukienslide Theo ID
        /// </summary>
        /// <param name="PK_sDanhmucsukienslideID">String:Danhmucsukienslide ID</param>
        /// <returns>DanhmucsukienslideEntity</returns>        
        public static DanhmucsukienslideEntity GetOne(String PK_sDanhmucsukienslideID)
        {

            if (PK_sDanhmucsukienslideID == "")
				throw new Exception(EX_ID_INVALID);
            return DanhmucsukienslideDAL.GetOne(PK_sDanhmucsukienslideID);
        }
        /// <summary>
        /// Lấy về List các Danhmucsukienslide
        /// </summary>
        /// <returns>List DanhmucsukienslideEntity:List Danhmucsukienslide Cần lấy</returns>
        public static List<DanhmucsukienslideEntity> GetAll()
        {
            return DanhmucsukienslideDAL.GetAll();
        }
        
        /// <summary>
        /// Kiểm tra và thêm mới Danhmucsukienslide
        /// </summary>
        /// <param name="entity">Entity</param>
        /// <returns>Int32: ID của Danhmucsukienslide Mới Thêm Vào</returns>
        public static Int32 Add(DanhmucsukienslideEntity entity)
        {
            checkLogic(entity);
            checkDuplicate(entity, false);
            checkFK(entity);
            return DanhmucsukienslideDAL.Add(entity);
        }
        /// <summary>
        /// Kiểm tra và chỉnh sửa Danhmucsukienslide
        /// </summary>
        /// <param name="entity">DanhmucsukienslideEntity</param>
        /// <returns>bool:kết quả thực hiện</returns>
        public static bool Edit(DanhmucsukienslideEntity entity)
        {
            checkExist(entity.PK_sDanhmucsukienslideID);
            checkLogic(entity);
            checkDuplicate(entity, true);
            checkFK(entity);
            return DanhmucsukienslideDAL.Edit(entity);
        }
        /// <summary>
        /// Kiểm tra và xoá Danhmucsukienslide
        /// </summary>
        /// <param name="PK_iDanhmucsukienslideID">Int16 : PK_iDanhmucsukienslideID</param>
        /// <returns>bool:kết quả thực hiện</returns>
        public static bool Remove(String PK_sDanhmucsukienslideID)
        {
            checkExist(PK_sDanhmucsukienslideID);
            return DanhmucsukienslideDAL.Remove(PK_sDanhmucsukienslideID);
        }
        #endregion
        #region Private Methods
        private static void checkExist(String PK_sDanhmucsukienslideID)
        {
            DanhmucsukienslideEntity oDanhmucsukienslide = DanhmucsukienslideDAL.GetOne(PK_sDanhmucsukienslideID);
            if(oDanhmucsukienslide==null)
                throw new Exception(EX_NOT_EXIST);
        }
        /// <summary>
        /// Kiểm tra logic Entity
        /// </summary>
        /// <param name="entity">DanhmucsukienslideEntity: entity</param>
        private static void checkLogic(DanhmucsukienslideEntity entity)
        {   
			if (String.IsNullOrEmpty(entity.sTensukien))
				throw new Exception(EX_STENSUKIEN_EMPTY);
        }
        /// <summary>
        /// Kiểm tra trùng lặp bản ghi
        /// </summary>
        /// <param name="entity">DanhmucsukienslideEntity: DanhmucsukienslideEntity</param>
        private static void checkDuplicate(DanhmucsukienslideEntity entity,bool checkPK)
        {
            /* 
            Example
            List<DanhmucsukienslideEntity> list = DanhmucsukienslideDAL.GetAll();
            if (list.Exists(
                delegate(DanhmucsukienslideEntity oldEntity)
                {
                    bool result =oldEntity.FIELD.Equals(entity.FIELD, StringComparison.OrdinalIgnoreCase);
                    if(checkPK)
                        result=result && oldEntity.PK_iDanhmucsukienslideID != entity.PK_iDanhmucsukienslideID;
                    return result;
                }
            ))
            {
                list.Clear();
                throw new Exception(EX_FIELD_EXISTED);
            }
            */
        }
        /// <summary>
        /// Kiểm tra tồn tại khóa ngoại
        /// </summary>
        /// <param name="entity">DanhmucsukienslideEntity:entity</param>
        private static void checkFK(DanhmucsukienslideEntity entity)
        {            
        }
        #endregion
    }
}
